package org.example.model.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author weigang
 * @create 2022-11-08 15:05
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@TableName(value = "sys_user")
public class SysUser implements Serializable {
    private static final long serialVersionUID = -7031724237702524153L;

    /**
     * 表id
     */
    @TableId(type = IdType.ASSIGN_ID)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long userId;

    /**
     * 用户名/itcode
     */
    @Size(max = 50, message = "length more than 50")
    @NotBlank(message = "not null")
    private String userName;

    /**
     * 密码
     */
    @Size(max = 256, message = "length more than 256")
    private String password;

    /**
     * 锁定标记（0 未锁定 1锁定）
     */
    @Range(min = 0, max = 32767, message = "between 0 and 32767")
    @NotNull(message = "not null")
    private Integer lockFlag;

    /**
     * 手机号
     */
    @Size(max = 20, message = "length more than 20")
    private String phone;

    /**
     * 邮箱
     */
    @Size(max = 50, message = "length more than 50")
    private String email;

    /**
     * 部门表id
     */
    @NotNull(message = "not null")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long deptId;

    /**
     * 最后登录时间
     */
    private LocalDateTime lastLoginTime;

    /**
     * 最后登录ip
     */
    @Size(max = 50, message = "length more than 50")
    private String lastLoginAddr;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime createTime;

    /**
     * 创建用户
     */
    @TableField(fill = FieldFill.INSERT)
    private String createBy;

    /**
     * 修改时间
     */
    @TableField(fill = FieldFill.UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private LocalDateTime updateTime;

    /**
     * 修改用户
     */
    private String updateBy;

    /**
     * 逻辑删除（1 删除 0 未删除）
     */
    @TableLogic
    private Integer isDeleted;

}
